﻿
using System;
namespace Inovout.Data.Domain
{
    public class DataObjectChildrenSet<TModel> : DataObjectSet<TModel>, IDataObjectChildrenSet<TModel> where TModel : class, ITreeDataObject<TModel>
    {

        public DataObjectChildrenSet(ITreeDataObject<TModel> parent)
        {
            Parent = parent as TModel;
            this.setParent = (c) =>
            {
                ITreeDataObject<TModel> child = c as ITreeDataObject<TModel>;
                child.Parent = this.Parent;
            };
        }
        public TModel Parent
        {
            get;
            private set;
        }
        private Action<TModel> setParent;

        public new virtual bool Add(TModel item)
        {
            if (base.Add(item))
            {
                if (setParent != null)
                {
                    setParent(item);
                }
                return true;
            }
            return false;
        }




    }
}
